package com.itheima.rabbitmq.listener;

import com.alibaba.fastjson.JSON;
import com.itheima.mapper.JournalMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
public class SpringQueueListener implements MessageListener {


    @Autowired
    private JournalMapper journalMapper;


    public void onMessage(Message message) {

        byte[] body = message.getBody();
        String s = new String(body);
        Map map = JSON.parseObject(s, Map.class);
        System.out.println(map);
        journalMapper.addJournal(map);


    }
}
